const fs = require('fs')
const path = require('path')

function read() {
  const arr = []
  const readStream = fs.createReadStream(path.resolve(__dirname, '0.txt'), {
    highWaterMark: 4
  })

  readStream.on('error', (err) => {
    console.log('发生异常')
  })

  readStream.on('open', (fd) => {
    console.log('文件已打开')
  })

  readStream.on('data', (chunk) => {
    arr.push(chunk)
  })

  readStream.on('end', () => {
    console.log('读取已完成')
  })
}

for (var i = 0; i < 100; ++i) {
  read()
}

console.log('结束')
